//
//  HLGudieController.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/17.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLGudieController.h"
#import "HLGudieCell.h"


@interface HLGudieController ()

@end

@implementation HLGudieController

static NSString * const reuseIdentifier = @"Cell";

//自定义类方法创建流式布局的collection
+ (instancetype)gudieControllerWithFlewLayout {
    //创建流式布局对象
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    //设置cell大小
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    //设置布局方向
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置cell的间距
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    //创建
    HLGudieController * gudie = [[HLGudieController alloc] initWithCollectionViewLayout:layout];
    //设置分页浏览
    gudie.collectionView.pagingEnabled = YES;
    //隐藏水平混动条
    gudie.collectionView.showsHorizontalScrollIndicator = NO;
    //取消弹簧效果
    gudie.collectionView.bounces = NO;
    return gudie;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // 注册cell类型
    [self.collectionView registerClass:[HLGudieCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark <UICollectionViewDataSource>


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return 4;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    //创建cell
    
    HLGudieCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    //修改属性
    cell.index = indexPath.item;
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    NSIndexPath *path = self.collectionView.indexPathsForVisibleItems.lastObject;
    //判断是最后一个cell
    if (path.item == 3) {
        HLGudieCell *gudieCell = (HLGudieCell *)[self.collectionView cellForItemAtIndexPath:path];
        //开启动画
        [gudieCell startBtnAnimation];
        
    }
}

@end



